package com.ruoyi.weixin.shop.controller;

import java.util.List;
import java.util.Arrays;

import com.ruoyi.weixin.shop.domain.vo.WxShopMenuAddBo;
import com.ruoyi.weixin.shop.domain.vo.WxShopMenuEditBo;
import com.ruoyi.weixin.shop.domain.vo.WxShopMenuQueryBo;
import com.ruoyi.weixin.shop.domain.vo.WxShopMenuVo;
import com.ruoyi.weixin.shop.service.IWxShopMenuService;
import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 微信商城菜单Controller
 *
 * @author ruoyi
 * @date 2021-07-14
 */
@Api(value = "微信商城菜单控制器", tags = {"微信商城菜单管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/wx/shop/menu")
public class WxShopMenuController extends BaseController {

	private final IWxShopMenuService iWxShopMenuService;

	/**
	 * 查询微信商城菜单列表
	 */
	@ApiOperation("查询微信商城菜单列表")
	@PreAuthorize("@ss.hasPermi('shop:menu:list')")
	@GetMapping("/list")
	public TableDataInfo<WxShopMenuVo> list(@Validated WxShopMenuQueryBo bo) {
		return iWxShopMenuService.queryPageList(bo);
	}

	/**
	 * 导出微信商城菜单列表
	 */
	@ApiOperation("导出微信商城菜单列表")
	@PreAuthorize("@ss.hasPermi('shop:menu:export')")
	@GetMapping("/export")
	public AjaxResult<WxShopMenuVo> export(@Validated WxShopMenuQueryBo bo) {
		List<WxShopMenuVo> list = iWxShopMenuService.queryList(bo);
		ExcelUtil<WxShopMenuVo> util = new ExcelUtil<WxShopMenuVo>(WxShopMenuVo.class);
		return util.exportExcel(list, "微信商城菜单");
	}

	/**
	 * 获取微信商城菜单详细信息
	 */
	@ApiOperation("获取微信商城菜单详细信息")
	@PreAuthorize("@ss.hasPermi('shop:menu:query')")
	@GetMapping("/{id}")
	public AjaxResult<WxShopMenuVo> getInfo(@NotNull(message = "主键不能为空")
											@PathVariable("id") Long id) {
		return AjaxResult.success(iWxShopMenuService.queryById(id));
	}

	/**
	 * 新增微信商城菜单
	 */
	@ApiOperation("新增微信商城菜单")
	@PreAuthorize("@ss.hasPermi('shop:menu:add')")
	@PostMapping()
	public AjaxResult<Void> add(@Validated @RequestBody WxShopMenuAddBo bo) {
		return toAjax(iWxShopMenuService.insertByAddBo(bo) ? 1 : 0);
	}

	/**
	 * 修改微信商城菜单
	 */
	@ApiOperation("修改微信商城菜单")
	@PreAuthorize("@ss.hasPermi('shop:menu:edit')")
	@PutMapping()
	public AjaxResult<Void> edit(@Validated @RequestBody WxShopMenuEditBo bo) {
		return toAjax(iWxShopMenuService.updateByEditBo(bo) ? 1 : 0);
	}

	/**
	 * 删除微信商城菜单
	 */
	@ApiOperation("删除微信商城菜单")
	@PreAuthorize("@ss.hasPermi('shop:menu:remove')")
	@DeleteMapping("/{ids}")
	public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
								   @PathVariable Long[] ids) {
		return toAjax(iWxShopMenuService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
	}
}
